package za.org.meraka.mxitstem.analysis;

import java.io.IOException;

import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;



public final class MxitStemFilter extends TokenFilter {
  private MxitStemmer stemmer;
  private TermAttribute termAtt;

  public MxitStemFilter(TokenStream in) {
    super(in);
    stemmer = new MxitStemmer();
    termAtt = (TermAttribute) addAttribute(TermAttribute.class);
  }

  public final boolean incrementToken() throws IOException {
    if (!input.incrementToken())
      return false;

	System.out.println("[" + termAtt.term() + "]");
	/*
    if (stemmer.stem(termAtt.termBuffer(), 0, termAtt.termLength()))
      termAtt.setTermBuffer(stemmer.getResultBuffer(), 0, stemmer.getResultLength());
	*/
    if ( MxitUtilities.compareWordAndStem(termAtt.term()) )
      termAtt.setTermBuffer(termAtt.term(), 0, termAtt.term().length());
    return true;
  }
}
